﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace YAPL.Util {
	public class ILVerifier {
		private const string VERIFICATION_OK_MESSAGE_TEMPLATE = "All Classes and Methods in {0} Verified.\r\n";
		private readonly string _peVerifyPath;

		public ILVerifier(string peVerifyPath) {
			_peVerifyPath = peVerifyPath;
		}

		public string PeVerifyPath {
			get { return _peVerifyPath; }
		}

		public string VerifyAssemply(string path) {
			var procStartInfo = new ProcessStartInfo(_peVerifyPath, "/NOLOGO " + path) {
				UseShellExecute = false,
				CreateNoWindow = true,
				RedirectStandardOutput = true};

			var verifyProcess = new Process {StartInfo = procStartInfo};
			verifyProcess.Start();

			var outputReader = verifyProcess.StandardOutput;
			var output = outputReader.ReadToEnd();
			return Encoding.Default.DecodeString(output, Encoding.GetEncoding(866));
		}
		public static string GetOkVerificationMessage(string path) {
			return string.Format(VERIFICATION_OK_MESSAGE_TEMPLATE, path);
		}
	}
}
